'''
# Coding:utf-8
# Project: online-exam
# Author: rtf
# Time: 2022-07-26 14:01:01
# FileName: profile.py
# Software: PyCharm
'''

from trump.utils import ok, fail
from trump.utils import get_user
from trump.query import get_item


async def ls(app, request):
    user = get_user(request)
    if user.get("role") == "STUDENT":
        college = await get_item(app.ctx.pool, "college", user.get("college_code"), column="code")
        specialty = await get_item(app.ctx.pool, "specialty", user.get("specialty_code"), column="code")
        user["college_name"] = college.get("name") if college else None
        user["specialty_name"] = specialty.get("name") if college else None
    elif user.get("role") == "TEACHER":
        college = await get_item(app.ctx.pool, "college", user.get("college_code"), column="code")
        user["college_name"] = college.get("name") if college else None
    return ok(user)


